{{ template "base" . }}

{{ define "title" }}
    {{ if .article.ID }}编辑文章: {{ .article.Title }}{{ else }}新建文章{{ end }}
{{ end }}

{{ define "content" }}
    <div class="admin-header">
        <div>
            <h2>
                {{ if .article.ID }}
                    编辑文章: {{ .article.Title }}
                {{ else }}
                    新建文章
                {{ end }}
            </h2>
            <p>欢迎, {{ .username }} | <a href="/admin/logout">退出</a></p>
        </div>
        <a href="/admin/articles" class="btn btn-secondary">返回列表</a>
    </div>
    
    <form method="POST" action="/admin/article/save">
        <input type="hidden" name="id" value="{{ .article.ID }}">
        
        <div class="form-group">
            <label for="title">标题</label>
            <input type="text" id="title" name="title" value="{{ .article.Title }}" required>
        </div>
        
        <div class="form-group">
            <label for="content">内容 (Markdown格式)</label>
            <textarea id="content" name="content" rows="15" required>{{ .article.Content }}</textarea>
        </div>
        
        <div class="form-group">
            <label>
                <input type="checkbox" name="published" {{ if .article.Published }}checked{{ end }}>
                发布文章
            </label>
        </div>
        
        <div class="form-actions">
            <button type="submit" class="btn">保存</button>
            <a href="/admin/articles" class="btn btn-secondary">取消</a>
        </div>
    </form>
{{ end }}